﻿using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UMLSynthesizer.CSharpAnalyzer.Elements;
using UMLSynthesizer.LangAnalyzer.Elements;

namespace UMLSynthesizer.CSharpAnalyzer.Helpers
{
    class CSharpElementWithParametersHelper
    {
        #region Fields

        IElementWithParametersBase elementWithParameter;
        SyntaxNode elementNode;
        IEnumerable<CSharpParameterVariableElement> _parameterList;

        #endregion

        #region Constructor
        public CSharpElementWithParametersHelper(
            IElementWithParametersBase elementWithParameter,
            BaseMethodDeclarationSyntax elementNode)
        {
            this.elementWithParameter = elementWithParameter;
            this.elementNode = elementNode;
        }
        public CSharpElementWithParametersHelper(
            IElementWithParametersBase elementWithParameter,
            DelegateDeclarationSyntax elementNode)
        {
            this.elementWithParameter = elementWithParameter;
            this.elementNode = elementNode;
        }

        #endregion

        #region Properties

        public IEnumerable<IParameterElement> ParameterList
        {
            get
            {
                if (_parameterList == null)
                {
                    if (elementNode as BaseMethodDeclarationSyntax != null)
                        _parameterList = new List<CSharpParameterVariableElement>(
                            from parameter in (elementNode as BaseMethodDeclarationSyntax).ParameterList.Parameters
                            select new CSharpParameterVariableElement(parameter, elementWithParameter));
                    if (elementNode as DelegateDeclarationSyntax != null)
                        _parameterList = new List<CSharpParameterVariableElement>(
                            from parameter in (elementNode as DelegateDeclarationSyntax).ParameterList.Parameters
                            select new CSharpParameterVariableElement(parameter, elementWithParameter));
                }
                return _parameterList;
            }
        }

        #endregion
    }
}
